package com.xinyi.reactivemvvm.sources.remote.impl;

import com.alibaba.fastjson.JSON;
import com.xinyi.httpdemo.execute.ExecuteAwait;
import com.xinyi.httpdemo.model.HttpMethod;
import com.xinyi.httpdemo.model.HttpParams;
import com.xinyi.httpdemo.model.RequestConfigData;
import com.xinyi.httpdemo.model.ResponseData;
import com.xinyi.reactivemvvm.consts.NetURL;
import com.xinyi.reactivemvvm.model.NeteaseCommentModel;
import com.xinyi.reactivemvvm.model.request.NeteaseCommentRequest;
import com.xinyi.reactivemvvm.sources.remote.NeteaseApi;

import javax.inject.Inject;

/**
 * @author 杨耿雷
 * @date 2024/9/23 22:04
 * @description 网抑云接口实现类
 */
public class NeteaseApiImpl implements NeteaseApi {

    @Inject
    public NeteaseApiImpl() { }

    @Override
    public ResponseData getNeteaseComment(NeteaseCommentRequest request) {
        // 创建请求配置数据
        RequestConfigData requestConfigData = new RequestConfigData();
        // 设置请求参数
        HttpParams params = new HttpParams();
        params.put("format", request.getFormat());
        requestConfigData.setParams(params);
        // 设置请求路径
        requestConfigData.setPath(NetURL.NETEASE_COMMENTS_URL);
        // 设置请求方式
        requestConfigData.setMethod(HttpMethod.GET);
        ResponseData responseData = ExecuteAwait.execute(requestConfigData);
        String data = responseData.getData().toString();
        // 解析数据
        responseData.setData(JSON.parseObject(data, NeteaseCommentModel.class));
        return responseData;
    }
}
